import {
  CoolController,
  BaseController,
  CoolTag,
  TagTypes,
} from '@cool-midway/core';
import { UserInfoEntity } from '../../entity/info';
import { ALL, Body, Inject, Post } from '@midwayjs/core';
import { UserInfoService } from '../../service/info';

/**
 * 用户信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: UserInfoEntity,
  service: UserInfoService,
  pageQueryOp: {
    fieldEq: ['a.role', 'a.agentLevel'],
    keyWordLikeFields: ['a.phone'],
  },
  listQueryOp: {
    fieldEq: ['a.role', 'a.agentLevel'],
    keyWordLikeFields: ['a.phone'],
  },
})
export class AdminUserInfoController extends BaseController {
  @Inject()
  ctx;

  @Inject()
  userInfoService: UserInfoService;

  // 创建商户
  @Post('/createMerchant', { summary: '创建商户' })
  async createMerchant(@Body(ALL) params: any) {
    return this.ok(await this.userInfoService.createMerchant(params));
  }

  // 申请代理
  @CoolTag(TagTypes.IGNORE_TOKEN)
  @Post('/createAgent', { summary: '申请代理' })
  async createAgent(@Body(ALL) params: any) {
    return this.ok(await this.userInfoService.createAgentNew(params));
  }
}
